<script type="text/javascript">
    /*
     $(document).ready(function() {
     var num_records = <?= $num_records ?>;
     var loaded_records = 0;        
     var loading  = false; //to prevents multipal ajax loads        
     
     $(window).scroll(function() { //detect page scroll
     
     if($(window).scrollTop() + $(window).height() == $(document).height())  //user scrolled to bottom of the page?
     {
     
     if(loaded_records >= num_records - 10) {
     $("#ajax_loader").hide();
     return;
     }                    
     
     if(num_records > 10 && loading==false) //there's more data to load
     {
     loading = true; //prevent further ajax loading
     loaded_records += 10;
     
     $.get("tim-kiem-ajax/" + $('#keyword').val() + "/" + loaded_records + "/" + num_records, function(data){
     $("#ajax_loader").show();
     $("#main_content").append(data);
     loading = false;
     }).fail(function() {
     $("#ajax_loader").hide();
     loading = false;
     });
     
     $("#ajax_loader").hide();
     
     }
     }
     });
     });
     */


    $(document).ready(function() {
        var num_records = <?= $num_records ?>;
        var loaded_records = 0;
        var filterType = <?= $filterType ?>;
        var cateId = <?= $cateId ?>;

        if (num_records <= 10) {
            $("#ajax_loader").hide();
            $("#more_button").hide();
        }

        $("#more_button").click(function() {

            loaded_records += 10;
            $("#ajax_loader").show();

            $.get("tim-kiem-ajax/" + $('#keyword').val() + "/" + loaded_records + "/" + num_records + "/" + filterType + "/" + cateId, function(data) {
                $("#main_content").append(data);
            }).fail(function() {
                $("#ajax_loader").hide();
            });

            $("#ajax_loader").hide();
            if (loaded_records >= num_records - 10)
                $("#more_button").hide();
        });

        $("input[type='checkbox']").change(function() {
            var checkedValue = $(this).val();
            if (checkedValue == 1) {
                if ($("#chkAll").is(':checked')) {
                    $('#chkTitle').prop('checked', false);
                    $('#chkShortDesc').prop('checked', false);
                    $('#chkFullDesc').prop('checked', false);
                }
            } else {
                $('#chkAll').prop('checked', false);
            }
        });


    })
</script>
<!-- tin moi nhat -->
<div id="latest-title">
    <span class="title"><?php echo $page_title; ?></span>
    <img src="<?php echo $img_url; ?>style/images/img28.gif">
    <div class="ico-social">
        <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $current_url; ?>&display=popup&ref=plugin" target="_blank"><img src="<?php echo $img_url; ?>style/images/imgfb.gif" width="16" height="16" border="0"></a>
        <a href="https://twitter.com/share" target="_blank"><img src="<?php echo $img_url; ?>style/images/imgtw.gif" width="16" height="16" border="0"></a>
        <a href="https://plus.google.com/share?url=<?php echo $current_url; ?>" target="_blank"><img src="<?php echo $img_url; ?>style/images/imggp.gif" width="16" height="16" border="0"></a>
        <a href="javascript:void(0);" onclick="return openPopup('contactForm')"><img src="<?php echo $img_url; ?>style/images/imgma.gif" width="16" height="16" border="0"></a>
        <a href="javascript:void(0);" onclick="javascript:window.print();"><img src="<?php echo $img_url; ?>style/images/imgpr.gif" width="16" height="16" border="0"></a>
        <span class="time">
            <?php
            //show date time Tieng Viet
            $str_search = array(
                "Mon",
                "Tue",
                "Wed",
                "Thu",
                "Fri",
                "Sat",
                "Sun"
            );
            $str_replace = array(
                "Th&#7913; hai",
                "Th&#7913; ba",
                "Th&#7913; t&#432;",
                "Th&#7913; n&#259;m",
                "Th&#7913; s&#225;u",
                "Th&#7913; b&#7843;y",
                "Ch&#7911; nh&#7853;t"
            );
            $timenow = gmdate("D, d/m/Y | H:i", time() + 7 * 3600);
            $timenow = str_replace($str_search, $str_replace, $timenow);
            echo $timenow;
            ?>      
        </span>
    </div>
</div>  
<div id="seperator"></div>

<!-- box advance search -->
<div class="wrapper-search">
    <div id="frm-search-2" style="display:block;">
        <form name="frmSearch2" id="frmSearch2" method="POST" action="<?php echo $base_url; ?>tim-kiem">
            <ul>
                <li>
                    <h2>Nội dung cần tìm</h2>
                </li>
                <li>
                    <input id="keyword" name="keyword" class="txt-search-1" type="text" value="<?php if (isset($keyword)) echo urldecode($keyword); ?>" placeholder="Gõ từ khóa tìm kiếm tại đây">
                </li>
                <li>
                    <label>Vị trí tìm kiếm</label>
                    <label class="chk-1"><input type="checkbox" id="chkAll" name="chkAll" value="1" <?php if ($chkAll) echo "checked='true'" ?>> Tất cả </label>
                    <label class="chk-1"><input type="checkbox" id="chkTitle" name="chkTitle" value="2" <?php if ($chkTitle) echo "checked='true'" ?>> Tiêu đề </label>
                    <label class="chk-1"><input type="checkbox" id="chkShortDesc" name="chkShortDesc" value="4" <?php if ($chkShortDesc) echo "checked='true'" ?>> Tóm tắt </label>
                    <label class="chk-1"><input type="checkbox" id="chkFullDesc" name="chkFullDesc" value="8" <?php if ($chkFullDesc) echo "checked='true'" ?>> Nội dung </label>
                </li>
                <li>&nbsp;</li>
                <li>&nbsp;</li>
                <li>
                <lable id="search-label">Phạm vi tìm kiếm &nbsp;&nbsp;&nbsp;&nbsp;</lable>
                <select class="sl-1" name="optCate" id="optCate">
                    <option value="0" <?php if ($cateId == '0') {
                echo ' selected="selected"';
            } ?>>Toàn bộ chuyên mục</option>
                    <option value="1" <?php if ($cateId == '1') {
                echo ' selected="selected"';
            } ?>>Tin XNK</option>
                    <option value="2" <?php if ($cateId == '2') {
                echo ' selected="selected"';
            } ?>>Văn bản pháp quy</option>
                    <option value="3" <?php if ($cateId == '3') {
                echo ' selected="selected"';
            } ?>>Kiến thức XNK</option>
                    <option value="4" <?php if ($cateId == '4') {
                echo ' selected="selected"';
            } ?>>Thủ tục hải quan</option>
                    <option value="5" <?php if ($cateId == '5') {
                echo ' selected="selected"';
            } ?>>Nghiệp vụ giao nhận</option>
                    <option value="6" <?php if ($cateId == '6') {
                echo ' selected="selected"';
            } ?>>Nghiệp vụ liên quan</option>
                </select>                
                <a class="btn-date calendar" href="#" title="date"></a>
                </li>
                <li>
                    <input type="submit" value="Tìm kiếm" class="btn-submit-2">
                </li>
            </ul>
        </form>
        <input id="ngay" type="hidden" readonly="" name="ngay">
    </div>

</div>

<!-- box: record đầu tiên -->
<?php
if (isset($aNews) && count($aNews) > 0) {
    $parent_cate_url = "";
    ?>    

    <div id="news-itemlist">
        <div class="item">
            <ul>
                <?php
                foreach ($aNews as $key => $item):
                    if ($item->parent_cate_url != "")
                        $parent_cate_url = $item->parent_cate_url;
                    ?>   
                    <li class="left"><a href="<?php echo $base_url . $parent_cate_url . $item->news_cate_url . "/" . $item->url . "-" . $item->news_id; ?>.html" class="title"><img src="<?php echo $img_url; ?>style/<?php echo $item->img_thumb2; ?>" width="140" height="90" border="0"></a></li>
                    <li class="right">
                        <a href="<?php echo $base_url . $parent_cate_url . $item->news_cate_url . "/" . $item->url . "-" . $item->news_id; ?>.html" class="title"><?php echo highlightWords($item->title, urldecode($keyword)); ?></a> 
                        <span class="time"><?php echo $item->display_date; ?></span>
                        <span class="content"><?php echo highlightWords($item->short_desc, $keyword); ?></span>
                    </li>          
                    <div class="clearfix"></div>
                    <div id="seperator2"></div>                 
        <?php
        $parent_cate_url = "";
    endforeach;
    ?>   
            </ul>                    
            <div id="main_content"></div>
            <div id="ajax_loader" style="display:none" align="center">
                <img src="<?php echo $img_url; ?>style/img/ajax-loader.gif">
            </div>
        </div>
    </div> 

    <div id="more_button">
        Xem thêm
    </div>
    <?php
}
else
    echo "<br><br><div align='center' class='nodata'>" . $page_nodata . "</div>";
?>     
<!-- end of FAQ -->
<br><br>